package com.example.im.ui.fragment

import android.content.Context
import android.os.Bundle
import android.view.View
import com.example.im.R
import com.example.im.callback.OnClickUserListener
import com.example.im.mvp.base.BasePresenter
import com.example.im.ui.abstracts.AbstractBaseFragment
import com.example.im.common.Constants
import com.example.im.entity.FriendOrRoom
import kotlinx.android.synthetic.main.fragment_user_center.*

class UserCentreFragment : AbstractBaseFragment<BasePresenter<*>>(), View.OnClickListener {


    private var friends: FriendOrRoom? = null

    private var mOnClickUserListener: OnClickUserListener? = null

    companion object {
        fun newInstance(friend: FriendOrRoom): UserCentreFragment {
            val bundle = Bundle()
            bundle.putSerializable(Constants.BUNDLE_T0_USER_DATA, friend)
            val fragment = UserCentreFragment()
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        mOnClickUserListener = context as OnClickUserListener
    }

    override val layoutId: Int
        get() = R.layout.fragment_user_center

    override fun initView() {

        this.friends = arguments!!.getSerializable(Constants.BUNDLE_T0_USER_DATA) as FriendOrRoom

        tv_user_nick_name_1.text = friends!!.nickname
        tv_user_nick_name_2.text = friends!!.nickname
        tv_user_name.text = friends!!.account

        tv_user_send_chat.setOnClickListener(this)
        tv_user_clear_chat.setOnClickListener(this)
        tv_user_delete.setOnClickListener(this)

    }

    override fun initPresenter() {

    }

    override fun initLazyLoad() {

    }

    override fun onClick(v: View?) {

        when (v!!.id) {
            R.id.tv_user_send_chat -> mOnClickUserListener!!.onClickSendChat(v, friends!!)
            R.id.tv_user_clear_chat -> mOnClickUserListener!!.onClickClearChat(v, friends!!)
            R.id.tv_user_delete -> mOnClickUserListener!!.onClickDelete(v, friends!!)
        }
    }

}